package com.org.Bibliotech;

import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.*;

public class LibraryTest {

    private  Book HeadFirstJava = new Book("Head First Java", "Kathy Sierra & Bert Bates", 2003);
    private Book AnnaKarenina = new Book("Anna Karenina", "Leo Tolstoy", 1877);


   private ArrayList<Book> books = new ArrayList<Book>();

    Movie schindlersList = new Movie("Schindler's List", 1993, "Steven Spielberg", 10);
    Movie amadeus = new Movie ("Amadeus", 1984, "Milos Forman", 10);

    private ArrayList<Movie> movies = new ArrayList<Movie>();



   @Test
   public void testGetAvailableBooks(){


       books.add(HeadFirstJava);
       books.add(AnnaKarenina);

       Library library = new Library(books);


        assertEquals(books, library.getAvailableBooks());

    }

    public void testGetAvailableMovies(){
        movies.add(amadeus);
        movies.add(schindlersList);

        Library library = new Library(books, movies);


        assertEquals(movies, library.getAvailableMovies());
    }

    @Test
    public void testCheckoutBook(){
        books.add(HeadFirstJava);
        books.add(AnnaKarenina);

        Library library = new Library(books);

        assertTrue(library.getAvailableBooks().contains(HeadFirstJava));
        assertFalse(library.getCheckedOutBooks().contains(HeadFirstJava));

        assertTrue(library.checkoutBook(HeadFirstJava));

        assertFalse(library.getAvailableBooks().contains(HeadFirstJava));
        assertTrue(library.getCheckedOutBooks().contains(HeadFirstJava));

    }

    @Test
    public void testCheckoutMovie(){
        books.add(HeadFirstJava);
        books.add(AnnaKarenina);

        movies.add(schindlersList);
        movies.add(amadeus);

        Library library = new Library(books, movies);

        assertTrue(library.getAvailableMovies().contains(schindlersList));
        assertFalse(library.getCheckedOutMovies().contains(schindlersList));

        assertTrue(library.checkoutMovie(schindlersList));

        assertFalse(library.getAvailableMovies().contains(schindlersList));
        assertTrue(library.getCheckedOutMovies().contains(schindlersList));

    }





    @Test
    public void testReturnBook(){
        books.add(HeadFirstJava);
        books.add(AnnaKarenina);

        Library library = new Library(books);

        assertTrue(library.checkoutBook(HeadFirstJava));
        assertFalse(library.getAvailableBooks().contains(HeadFirstJava));
        assertTrue(library.getCheckedOutBooks().contains(HeadFirstJava));

        assertTrue(library.returnBook(HeadFirstJava));

        assertTrue(library.getAvailableBooks().contains(HeadFirstJava));
        assertFalse(library.getCheckedOutBooks().contains(HeadFirstJava));

    }

}